#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 30, M = 30;
int n, m;
int a[N][M], t[N][M];

const int fx[5] = {0, 0, 1, 0, -1}, fy[5] = {0, 1, 0, -1, 0};

void dj(int x, int y) {
  for (int i = 0; i <= 4; i++) {
    int tx = x + fx[i], ty = y + fy[i];
    if (tx < 1 || tx > n)
      continue;
    if (ty < 1 || ty > m)
      continue;
    t[tx][ty]  = !t[tx][ty];
    // t[tx][ty] ^= 1;
  }
}

int check(int st) {
  int result = 0;
  memcpy(t, a, sizeof(a)); // 勿忘
  for (int i = 0; i < m; i++) {
    if ((st >> i) & 1) {
      dj(1, i + 1);
      result++;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (t[i - 1][j]) {
        dj(i, j);
        result++;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (t[n][i])
      return -1;
  }
  return result;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j] ;
    }
  }

  int ans = INF;
  for (int i = 0; i < (1 << m); i++) {
    int k = check(i);
    if (k != -1) {
      ans = min(ans, k);
    }
  }

  if (ans != INF)
    printf("%d\n", ans);
  else
    puts("Impossible");
  return 0;
}